package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {


   

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /*
     * 向菜品表中添加数据
     * */

    void insert(Dish dish);

    /*
     * 菜品分页查询
     * */
    Page<DishVO> pagequary(DishPageQueryDTO dishPageQueryDTO);


    /*
    * 根据Id查询员工
    * */
    @Select("select * from dish where id =#{id}")
    Dish getByid(Long id);

    /*
    * 根据Id删除员工
    * */
    @Delete("delete  from dish where id =#{id}")
    void deleteByid(Long id);

    /*
    *根据Id来动态修改菜品
    * */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);


    List<Dish> list(Dish dish);


    /*
    * 根据菜品ID来寻找菜品
    * */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    @Select("select count(id) from dish where status = #{status}")
    Integer CountDishByStatus(int i);
}
